var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "maishu-ui-toolkit", "mobile/services/shoppingService", "react", "mobile/site", "mobile/controls/button", "mobile/controls/imageBox", "controls/spiner-component"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const ui = require("maishu-ui-toolkit");
    const shoppingService_1 = require("mobile/services/shoppingService");
    const React = require("react");
    const site_1 = require("mobile/site");
    const button_1 = require("mobile/controls/button");
    const imageBox_1 = require("mobile/controls/imageBox");
    const spiner_component_1 = require("controls/spiner-component");
    class OrderDetailPage extends spiner_component_1.SpinerComponent {
        constructor(props) {
            super(props);
            this.state = { order: this.props.order };
            this.shopping = this.props.createService(shoppingService_1.ShoppingService);
        }
        purchase() {
            return Promise.reject(null);
        }
        confirmReceived() {
            return Promise.reject(null);
        }
        cancelOrder(order) {
            return this.shopping.cancelOrder(order.Id).then((data) => {
                order.Status = data.Status;
                this.setState(this.state);
            });
        }
        loadData() {
            return __awaiter(this, void 0, void 0, function* () {
                let order = yield this.shopping.order(this.props.data.id);
                return { order };
            });
        }
        render() {
            let order = this.state.order;
            return React.createElement(React.Fragment, null,
                React.createElement("header", null, site_1.defaultNavBar(this.props.source, { title: '订单详情' })),
                React.createElement("section", null,
                    React.createElement("div", { className: "container order", style: { paddingTop: 10 } },
                        React.createElement("div", { className: "list" },
                            React.createElement("div", { className: "form-group" },
                                React.createElement("label", null, "\u8BA2\u5355\u72B6\u6001\uFF1A"),
                                React.createElement("span", { style: { color: '#f70' } }, this.shopping.orderStatusText(order.Status))),
                            React.createElement("div", { className: "form-group" },
                                React.createElement("label", null, "\u8BA2\u5355\u7F16\u53F7\uFF1A"),
                                React.createElement("span", null, order.Serial)),
                            React.createElement("div", { className: "form-group" },
                                React.createElement("label", { className: "pull-left" }, "\u8BA2\u5355\u603B\u8BA1\uFF1A"),
                                React.createElement("div", null,
                                    React.createElement("span", { className: "price" },
                                        "\u00A5",
                                        order.Sum.toFixed(2)),
                                    React.createElement("span", { style: { paddingLeft: 10 } },
                                        "(\u8FD0\u8D39\uFF1A\u00A5",
                                        order.Freight.toFixed(2),
                                        ")")),
                                React.createElement("div", { className: "clearfix" })),
                            React.createElement("div", { className: "form-group" },
                                React.createElement("label", { className: "pull-left" }, "\u6536\u8D27\u4FE1\u606F\uFF1A"),
                                React.createElement("div", { style: { marginLeft: 70 } }, order.ReceiptAddress),
                                React.createElement("div", { className: "clearfix" })),
                            React.createElement("div", { className: "form-group" },
                                React.createElement("label", null, "\u4E0B\u5355\u65F6\u95F4\uFF1A"),
                                React.createElement("span", null, site_1.formatDate(order.OrderDate))),
                            order.Status == 'WaitingForPayment' ?
                                React.createElement("div", { className: "form-group" },
                                    React.createElement(button_1.Button, { onClick: () => this.purchase(), className: "btn btn-block btn-primary" }, "\u5FAE\u4FE1\u652F\u4ED8")) : null,
                            order.Status == 'Send' ?
                                React.createElement("div", { className: "form-group" },
                                    React.createElement(button_1.Button, { onClick: () => this.confirmReceived(), confirm: '你确定收到货了吗？', className: "btn btn-primary btn-block" }, "\u786E\u8BA4\u6536\u8D27")) : null)),
                    React.createElement("div", { "data-bind": "visible:expressCompany", className: "container order", style: { display: 'none' } },
                        React.createElement("h4", { className: "light" }, "\u7269\u6D41\u4FE1\u606F"),
                        React.createElement("div", { className: "list" },
                            React.createElement("div", { className: "box padding-lr-15" },
                                React.createElement("p", null,
                                    "\u5FEB\u9012\u516C\u53F8\uFF1A",
                                    React.createElement("span", { "data-bind": "text:expressCompany" })),
                                React.createElement("p", null,
                                    "\u5FEB\u9012\u5355\u53F7\uFF1A",
                                    React.createElement("span", { "data-bind": "text:expressBillNo" }))))),
                    React.createElement("div", { "data-bind": "with:order", className: "container order" },
                        React.createElement("div", null,
                            React.createElement("h4", { className: "text-primary", style: { fontWeight: 'bold' } }, "\u8D2D\u7269\u6E05\u5355")),
                        React.createElement("div", { className: "list" }, order.OrderDetails.map((o) => (React.createElement("div", { key: o.ProductId },
                            React.createElement("hr", { className: "row" }),
                            React.createElement("div", { className: "row" },
                                React.createElement("div", { className: "col-xs-4", style: { paddingRight: 0 } },
                                    React.createElement("a", { href: `#home_product?id=${o.ProductId}` },
                                        React.createElement(imageBox_1.ImageBox, { src: o.ImageUrl, className: "img-responsive" }))),
                                React.createElement("div", { className: "col-xs-8" },
                                    React.createElement("a", { href: "#", className: "title" }, o.ProductName),
                                    React.createElement("div", null,
                                        "\u4EF7\u683C\uFF1A",
                                        React.createElement("span", { className: "price", "data-bind": "money:Price" },
                                            "\u00A5",
                                            o.Price.toFixed(2))),
                                    React.createElement("div", null,
                                        "\u6570\u91CF\uFF1A",
                                        React.createElement("span", { className: "price", "data-bind": "text:Quantity" }, o.Quantity))))))))),
                    order.Status == 'WaitingForPayment' ?
                        React.createElement("div", { "data-bind": "with:order", className: "container", style: { paddingTop: 10, paddingBottom: 20 } },
                            React.createElement("button", { onClick: () => this.cancelOrder(order), ref: (o) => {
                                    if (!o)
                                        return;
                                    o.onclick = ui.buttonOnClick(() => {
                                        return this.shopping.cancelOrder(order.Id);
                                    }, { confirm: '确定取消该定单吗', toast: '订单已经取消' });
                                }, className: "btn btn-block btn-default" }, "\u53D6\u6D88\u8BA2\u5355")) : null));
        }
    }
    exports.default = OrderDetailPage;
});
